package cqie.edu.homework2.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cqie.edu.homework2.domain.po.TUser;
import cqie.edu.homework2.service.TUserService;
import cqie.edu.homework2.mapper.TUserMapper;
import cqie.edu.homework2.util.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 86182
* @description 针对表【t_user(用户基本信息表)】的数据库操作Service实现
* @createDate 2025-03-26 17:58:06
*/
@Service
public class TUserServiceImpl extends ServiceImpl<TUserMapper, TUser>
    implements TUserService{

    @Autowired
    private TUserMapper tUserMapper;
    @Override
    public Long insert1(TUser user) {
        String password = user.getPassword();

        String newPassword = MD5.MD5encrypt(password);

        //将加密后的密码存放到数据库中
        user.setPassword(newPassword);

        Long ans = tUserMapper.insert1(user);
        return ans;
    }

    @Override
    public Boolean verUser(TUser user) {
        String username = user.getUsername();
        String password = user.getPassword();

        TUser tUser = tUserMapper.selectByUsername(username);
        if(tUser == null){
            return false;
        }

        String vpassword = MD5.MD5encrypt(password);
        System.out.println(vpassword);
        if(vpassword.equals(tUser.getPassword())){
            return true;
        }else
            return false;

    }
}




